package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.bean.SetmealDish;
import com.itheima.mapper.SetMealDishMapper;
import com.itheima.service.SetMealDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author hebing
 * @version 1.0
 */
@Service
@Transactional
public class SetMealDishServiceImpl implements SetMealDishService {
    @Autowired
    private SetMealDishMapper setMealDishMapper;
    /**
     * 添加
     *
     * @param setmealDish
     * @return
     */
    @Override
    public int addSetMealDish(SetmealDish setmealDish) {
        //向setMealDish表中添加数据
        int rows = setMealDishMapper.updateById(setmealDish);
        return rows;
    }

    /**
     * 根据setmealId查询都有哪些菜品
     *
     * @param id
     * @return
     */
    @Override
    public List<SetmealDish> selectBySetmealId(Long id) {
        //构建查询条件
        LambdaQueryWrapper<SetmealDish> lqw=new LambdaQueryWrapper<>();
        lqw.eq(id!=null,SetmealDish::getSetmealId,id);
        //查询
        List<SetmealDish> setmealDishList = setMealDishMapper.selectList(lqw);
        return setmealDishList;
    }
}
